//
//  CWMediaCapture.h
//  CWDevelop
//
//  Created by LittoCats on 7/7/14.
//  Copyright (c) 2014 Littocats. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>

@class CWMediaStreamCapturePreview;

typedef NS_ENUM(NSInteger, CWMediaStreamCaptureOptions) {
    CWMediaStreamCaptureOptionsDefault            = 1 | 1 << 1,
    CWMediaStreamCaptureOptionsVideo              = 1,
    CWMediaStreamCaptureOptionsAudio              = 1 << 1
};
@interface CWMediaStreamCapture : NSObject

@property (nonatomic, readonly) CWMediaStreamCaptureOptions options;

/**
 *
 */
@property (nonatomic, setter = setCameraPosition:, getter = cameraPosition) AVCaptureDevicePosition cameraPosition;

/**
 *
 */
@property (nonatomic, setter = setFlashMode:, getter = flashMode) AVCaptureFlashMode flashMode;

- (void)start;
- (void)pause:(BOOL)isPause;
- (void)stop;

/**
 *  because capture dosen't work on main_queue (work on it's session_queue), 
    so ,if you need to work with UI ,you must dispatch your operation to main_queue
 */
+ (CWMediaStreamCapture *)captureWithOptions:(CWMediaStreamCaptureOptions)options
                         dataProcessor:(void (^)(CMSampleBufferRef sampleBufferRef, NSString *mediaType))dataProcessor;

#pragma mark- camera control
/**
 *  focus with the point in preview
 */
- (void)focusAtPreviewPoint:(CGPoint)pointInPreview;

/**
 *
 */
- (void)focusWithMode:(AVCaptureFocusMode)focusMode
       exposeWithMode:(AVCaptureExposureMode)exposureMode
        atDevicePoint:(CGPoint)point
monitorSubjectAreaChange:(BOOL)monitorSubjectAreaChange;
@end

@interface CWMediaStreamCapturePreview : UIView

@property (nonatomic, readonly, strong) CWMediaStreamCapture *mediaStreamcapture;

@property (nonatomic, getter = videoGravity, setter = setVideoGravity:) NSString *videoGravity;

+ (instancetype)previewWithMediaStreamCapture:(CWMediaStreamCapture *)capture size:(CGSize)size;

@end

/*
 @function	CGImageCreateWithCVPixelBuffer
 @abstract	Creates a CGImageRef with a sample buffer.
 */
CGImageRef CGImageCreateWithCVPixelBuffer(CVPixelBufferRef pixelBuffer);
/*!
 @function	CMSampleBufferCreateCopyWithTimeOffset
 @abstract	Creates a CMSampleBuffer with new timing information from another sample buffer.
 @discussion	This emulates CMSampleBufferCreateCopy, but changes the timing.
 
 On return, the caller owns the returned CMSampleBuffer, and must release it when done with it.
 
 */
CMSampleBufferRef CMSampleBufferCreateCopyWithTimeOffset(CMSampleBufferRef sampleBuffer, CMTime timeOffset);